const SMB2 = require('./../../../smb2/lib/smb2');
const eventClass = require('./eventClass');

const path_ = eval('require')('path');
const fs = eval('require')('fs');

const smb2Client = new SMB2({
    share: '\\\\11.11.11.74\\dd',
     domain: 'domain',
     username: 'BigLake',
     password: 'Deadin09',
     autoCloseTimeout: 1000 * 60 * 60 * 24,
});

class smb2 extends eventClass {
    constructor() {
        super('smb2');
        this.smb2Client = null;
        this.config = {
            share: '\\\\11.11.11.74\\dd',
            domain: 'domain',
            username: 'BigLake',
            password: 'Deadin09',
            autoCloseTimeout: 1000 * 60 * 60 * 24,
        };
    }

    checkAndConnect() {
        if (this.smb2Client || this.smb2Client.connected) {
            return this;
        }
        this.smb2Client = new SMB2(config);
        return this;
    }

    readdir(path, cb) {
        this.checkAndConnect()
            .smb2Client
            .readdir(path_.normalize(path), (err, files) => {
                this.returnMethod(cb, { err, data: files });
            });
    }

    // todo : smb2 附带的代码无法跑起来
    writeFile() {
    }
}

module.exports = dirClass;
